/**
 * Created by yangh on 2016/09/14.
 */
var main = {};
var myScroll;
(function ($) {
	main.init = function () {
		/*
		document.addEventListener('touchmove', function (e) {
			e.preventDefault();
		}, false);
		*/
	};

	/**
	 * @func move()
	 * @desc 监听滚动条的位置，异步加载列表
	 */
	function move() {
		if (this.y < main.max - 80) {
			$("#tip").hide();
			$("#loading").show();

			//加载数据
			main.loadData(".evaluationList");
			
			this.refresh();
			main.max = this.maxScrollY;
			console.log(main.max);

			$("#loading").hide();
			$("#tip").show();
		}
	}

	/**
	 * @func main.scroll()
	 * @desc 配置iscroll插件
	 */
	main.scroll = function () {
		myScroll = new IScroll("#wrapper", {probeType: 3, mouseWheel: true, click: true, preventDefault: false});

		main.max = myScroll.maxScrollY;
		/*console.log(main.max);*/

		myScroll.on("scroll", move);
	}
	
	
	 /** 
     * function loadData 加载数据
     */
    main.loadData = function(target){
    	//ajax begin
    	 var topicid=$("#topicid").val();
    	 var index = -1;
    	 if($(target+" li").length!=0){
    		 index=$(target+" li:last").data("id");
    	 }
         var html = "";
         $.ajax({
     		type:"post",
     		async:true, 
        	url:path+"/bbs/reply/more",
        	data:{
        		topicid:topicid,
        		index:index
        	},
     		success:function(data){	
     			if('000' == data.code){
     				var html = "";
     				for (var i = 0; i < data.result.length; i++) {
     					var reply = data.result[i];
     					html +="<li class=\"evaluation\"  data-id='"+reply.id+"'>";
     					html +="	<div class=\"img\"><img src='"+reply.headimgurl+"' ></div>";
     					html +="	<div class=\"nickname\">"+reply.nickname+"</div>";
     					html +="	<div class=\"date\">"+reply.createTime+"</div>";
     					html +="<p class=\"content\">"+reply.content+"</p>";
     					html +="</li>";
     				}	
     				//加载
     				$(target).append(html);
     				
     				myScroll.refresh();
     	            main.max = myScroll.maxScrollY;
     			}
     		}
     	})
   		//ajax end
    }
    
    
	
})(jQuery);

main.init();
main.scroll();
//加载数据
main.loadData(".evaluationList");

window.onload = function () {
	
};